package org.yu;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.loading.FMLEnvironment;
import net.minecraftforge.fml.loading.FMLLoader;
import org.jetbrains.annotations.NotNull;
import org.yu.api.register.LazyRegistry;
import org.yu.api.register.MenuTypeBuilder;
import org.yu.register.*;
import software.bernie.geckolib3.GeckoLib;

import static org.yu.Yu.MODID;

// The value here should match an entry in the META-INF/mods.toml file
@Mod(MODID)
public final class Yu {
    public static final String MODID="yu";
    private static Yu instance;
    public static final CreativeModeTab TAB=new CreativeModeTab(MODID) {
        @NotNull
        @Override
        public ItemStack makeIcon() {
            return new ItemStack(ItemRegister.fireSeed);
        }
    };
    public static final LazyRegistry LAZYREGISTRY=new LazyRegistry(MODID,TAB);
    public Yu() {
        super();
        instance = this;
        MobEffectRegister.init();
        ItemRegister.init();
        BlockRegister.init();
        MachineRegistry.init();
        EntityRegister.init();
        SoundEventRegistry.init();
        MenuTypeRegister.init();
        GeckoLib.initialize();
        RecipeRegister.init();
        LAZYREGISTRY.executeWhenCommonSetup(ModConfig::registerConfig);
        LAZYREGISTRY.executeWhenCommonSetup(ItemData::init);
        MinecraftForge.EVENT_BUS.addListener(this::onToolTip);
        if(!FMLEnvironment.production)
            ModLanguages.init();
    }
    private void onToolTip(ItemTooltipEvent event){
        var item=event.getItemStack();
        var map=ItemData.getAttribute(item.getItem());
        if(map!=null){
            event.getToolTip().add(new TranslatableComponent("tips.CanMixed"));
            if(event.getPlayer()!=null&& Screen.hasShiftDown())
            map.forEach(((holder, integer) -> {
                event.getToolTip().add(new TextComponent(holder.textKey));
            }));
        }
        if(item.is(ItemRegister.danYao.asItem())){
            item.getCapability(CapabilityRegister.MIXED_ITEM).ifPresent(mixedCapability -> {
                mixedCapability.getItemMixedNames().forEach((name,size)->{
                    event.getToolTip().add(new TextComponent(name+" X "+size));
                });
            });
        }
    }
    public static Yu getInstance() {
        return instance;
    }



}
